﻿namespace KAs.Application.Contract.Dto;

// 此处及请求也可根据不同的api类型封装不同的类，如：OpenApi对外开放接口、MobileApi对移动端开放接口、CommonApi等

/// <summary>
/// api统一返回对象
/// </summary>
/// <typeparam name="T"></typeparam>
/// <remarks>
/// 保证返回对象的高度统一，便于前端的对接。
/// </remarks>
public class ApiResult<T>
{
    /// <summary>
    /// 是否成功
    /// </summary>
    public bool Success { get; set; }
    /// <summary>
    /// 状态码
    /// </summary>
    public string StatusCode { get; set; }
    /// <summary>
    /// 信息
    /// </summary>
    public string Message { get; set; }
    /// <summary>
    /// 返回数据
    /// </summary>
    public T Data { get; set; }

    public static ApiResult<T> IsSuccess(T data = default, string msg = "", string code = "0")
    {
        return new ApiResult<T> { Success = true, StatusCode = code, Message = msg, Data = data };
    }
    public static ApiResult<T> IsError(string msg = "", string code = "1", T data = default)
    {
        return new ApiResult<T> { Success = false, StatusCode = code, Message = msg, Data = data };
    }
}
